<?php

/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * 
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
define('DIRECTORIO_DE_ARCHIVOS',  '..' . DS . WEBROOT_DIR . DS. 'archivos/' );
define('DIRECTORIO_DE_ARCHIVOS_APROBADOS', '../webroot/documentos_aceptados/');


define('SOLICITUD_TIPO_MODIFICACION', 'Modificacion');
define('SOLICITUD_TIPO_CONSULTA', 'Consulta');
define('SOLICITUD_ESTADO_APROBADO', 'Aprobado');
define('SOLICITUD_ESTADO_PENDIENTE', 'Pendiente');
define('SOLICITUD_ESTADO_RECHAZADO', 'Rechazado');
define('SOLICITUD_ESTADO_MODIFICACION_COMPLETA', 'Modificacion Completa');
define('SOLICITUD_ESTADO_MODIFICANDO', 'Modificando');


class AppController extends Controller {

    public $components = array(
        'Session','Auth'   
    );
   
    

   
    public function beforeFilter() {
        parent::beforeFilter();
        $usuario = $this->Auth->user();
        if ($usuario['role'] === 'admin') {
        
          $this->set('cerrar_sesion', 'users/logout' );
          
          
           $this->set('usuario', $usuario['username']);
            $this->layout = 'default';
         
        } else {
        
        
                   $this->set('usuario', $usuario['username']);
        
        $this->set('cerrar_sesion', 'users/logout' );
        
        
        
            $this->layout = 'default_usuario';
        }
    }

    public function isAuthorized($user) {


        if (isset($user['role']) && $user['role'] === 'admin') {
            

            return true;
        }

        if (isset($user['role']) && $user['role'] === 'user') {
            
            return true;
        }

        debug($this->layout);


        return false; // The rest don't
    }
    
    

}
